package cn.kgc.controller;

import cn.kgc.pojo.Education;
import cn.kgc.pojo.Jobposting;
import cn.kgc.service.EducationService;
import cn.kgc.service.JobpostingService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.Serializable;
import java.util.List;

@Controller
public class JobpostingController {
    @Reference
    private EducationService educationService;
    @Reference
    private JobpostingService jobpostingService;

    //获取学历下拉框
    @RequestMapping("/getEducation.json")
    @ResponseBody
    public List<Education> getEducation(){
        return educationService.findAll();
    }

    //处理提交的招聘信息
    @RequestMapping("/saveJobposting.json")
    @ResponseBody
    public Integer saveJobposting(Jobposting jobposting){
      //   jobposting.setUserid(1);
        //jobposting.setWorkNature("全职");
        jobposting.setMonthly("2-5");
        jobposting.setState(1);
        jobposting.setMisc("hhhhhh");
        Integer count=jobpostingService.save(jobposting);
        if(count>0){
            return 1;
        }else{
            return -1;
        }
    }


    //处理当日发送招聘信息数量
    @RequestMapping("/getCount.json")
    @ResponseBody
    private String getCount(){
        Integer currentCount=jobpostingService.getCount();
        Integer remains=5-currentCount;
        return "{\"currentCount\":"+currentCount+",\"remains\":"+remains+"}";
    }

    //获取未审核的招聘信息
    @RequestMapping("/getNoshene.json")
    @ResponseBody
    private List<Jobposting> getJobposingByNoShenhe(Integer userId){
        return jobpostingService.getJbposting(userId);
    }

    //获取已审核的招聘信息
    @RequestMapping("/getHasshene.json")
    @ResponseBody
    private List<Jobposting> getJobposingByHasShenhe(Integer userId){
        return jobpostingService.getHasJbposting(userId);
    }

    //获取审核不合格的招聘信息
    @RequestMapping("/getsheneNo.json")
    @ResponseBody
    private List<Jobposting> getJobposingByShenheNO(Integer userId){
        return jobpostingService.getNoJbposting(userId);
    }

    //获取已下架的招聘信息
    @RequestMapping("/getXiajiaJobposting.json")
    @ResponseBody
    private List<Jobposting> getjobpostingXiajia(Integer userId){
        return jobpostingService.getJbpostingXiajia(userId);
    }

    //更改简历状态(上架、下架、删除)
    @RequestMapping("/updateResume.json")
    @ResponseBody
    private Integer updatejobposting(Integer resumeId,Integer state){
        Integer count=jobpostingService.updateJobposting(resumeId,state);
        if(count>0){
            return 1;
        }else{
            return -1;
        }
    }

    //根据id查看招聘信息
    @RequestMapping("/showResume.json")
    @ResponseBody
    private List<Jobposting> getjobpostingByresumeId(Integer resumeId){
        return jobpostingService.findById(resumeId);
    }
}
